num_list = [1, 8, 10, 89, 1000, 1234]
find_num = 10


def binary_search(my_list, find_val):
    """
    功能：完成二分查找
    :param my_list:
    :param find_val:
    :return:
    """
    find_index = -1
    left_index, right_index = 0, len(num_list) - 1

    while left_index <= right_index:
        middle_index = (right_index + left_index) // 2

        if find_val > my_list[middle_index]:
            left_index = middle_index + 1
        elif find_val < my_list[middle_index]:
            right_index = middle_index - 1
        else:
            find_index = middle_index
            break

    return find_index


res_index = binary_search(num_list, find_num)
print(f"res_index = {res_index}")
